/*
 *  MTouchware_handlers.c
 *
 *  This code handles received messages via the TUIO_receiver.
 *
 *  Copyright (C) 2010 LIMSI-CNRS (Orsay-France) and EFREI (Paris-France)
 *
 *  Authors: Rami Ajaj, Nicolas Flasque and Frederic Vernier.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation; either version 2.1 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  $Id$
 */

#include <sys/time.h>
#include "TuioDumper/MTouchware_dump_handlers.h"

/* catch any incoming messages and display them. returning 1 means that the
 * message has not been fully handled and the server should try other methods */
int generic_dumper(const char *path, const char *types, lo_arg **argv,
		    int argc, void *data, void *user_data)
{

    FILE *nf_dumpfile = (FILE *)user_data;

    int nf_argnum;

#ifdef WITH_TIME
    struct timeval nf_tv;
    struct timezone nf_tz;
    gettimeofday(&nf_tv,&nf_tz);
    fprintf(nf_dumpfile,"%ld ",nf_tv.tv_sec*1000000L+nf_tv.tv_usec);
#endif

    fprintf(nf_dumpfile,"%s",path);

    for(nf_argnum=0; nf_argnum < argc; nf_argnum++)
    {
            switch(types[nf_argnum])
            {
                    case 'i':
                        fprintf(nf_dumpfile," %d",argv[nf_argnum]->i);
                    break;

                    case 'f' :
                        fprintf(nf_dumpfile," %f",argv[nf_argnum]->f);
                    break;

                    case 's' :
                        fprintf(nf_dumpfile," %s",&argv[nf_argnum]->s);
                    break;

                    default :
                    break;
            }

    }

    fprintf(nf_dumpfile,"\n");

    return 0;
}

